<?php
class ControllerSurveyAnswer extends Controller {
	private $error = array();

  	public function index() {
		$this->load->language('survey/answer');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('survey/answer');

    	$this->getList();
  	}
	
  	public function insert() {
		$this->load->language('survey/answer');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('survey/answer');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
      	  	$this->model_survey_answer->addAnswer($this->request->post);
			
			$this->session->data['success'] = $this->language->get('text_success');
		  
			$url = '';
			
			if (isset($this->request->get['filter_answer_id'])) {
				$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
			}
			
			if (isset($this->request->get['filter_customer'])) {
				$url .= '&filter_customer=' . $this->request->get['filter_customer'];
			}
												
			if (isset($this->request->get['filter_answer_status_id'])) {
				$url .= '&filter_answer_status_id=' . $this->request->get['filter_answer_status_id'];
			}
			
			if (isset($this->request->get['filter_total'])) {
				$url .= '&filter_total=' . $this->request->get['filter_total'];
			}
						
			if (isset($this->request->get['filter_date_added'])) {
				$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
			}
			
			if (isset($this->request->get['filter_date_modified'])) {
				$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
			}
													
			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['answer'])) {
				$url .= '&answer=' . $this->request->get['answer'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}
			
			$this->redirect($this->url->link('sale/return', 'token=' . $this->session->data['token'] . $url, 'SSL'));
		}
		
    	$this->getForm();
  	}
	
  	public function update() {
		$this->load->language('survey/answer');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('survey/answer');
    	
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
			$this->model_survey_answer->editAnswer($this->request->get['answer_id'], $this->request->post);
	  		
			$this->session->data['success'] = $this->language->get('text_success');
	  
			$url = '';

			if (isset($this->request->get['filter_answer_id'])) {
				$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
			}
			
			if (isset($this->request->get['filter_customer'])) {
				$url .= '&filter_customer=' . $this->request->get['filter_customer'];
			}
												
			if (isset($this->request->get['filter_answer_status_id'])) {
				$url .= '&filter_answer_status_id=' . $this->request->get['filter_answer_status_id'];
			}
			
			if (isset($this->request->get['filter_total'])) {
				$url .= '&filter_total=' . $this->request->get['filter_total'];
			}
						
			if (isset($this->request->get['filter_date_added'])) {
				$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
			}
			
			if (isset($this->request->get['filter_date_modified'])) {
				$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
			}
													
			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['answer'])) {
				$url .= '&answer=' . $this->request->get['answer'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}
			
			$this->redirect($this->url->link('sale/return', 'token=' . $this->session->data['token'] . $url, 'SSL'));
		}
		
    	$this->getForm();
  	}
	
  	public function delete() {
		$this->load->language('survey/answer');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('survey/answer');

    	if (isset($this->request->post['selected']) && ($this->validateDelete())) {
			foreach ($this->request->post['selected'] as $answer_id) {
				$this->model_survey_answer->deleteAnswer($answer_id);
			}

			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['filter_answer_id'])) {
				$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
			}
			
			if (isset($this->request->get['filter_customer'])) {
				$url .= '&filter_customer=' . $this->request->get['filter_customer'];
			}
												
			if (isset($this->request->get['filter_answer_status_id'])) {
				$url .= '&filter_answer_status_id=' . $this->request->get['filter_answer_status_id'];
			}
			
			if (isset($this->request->get['filter_total'])) {
				$url .= '&filter_total=' . $this->request->get['filter_total'];
			}
						
			if (isset($this->request->get['filter_date_added'])) {
				$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
			}
			
			if (isset($this->request->get['filter_date_modified'])) {
				$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
			}
													
			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['answer'])) {
				$url .= '&answer=' . $this->request->get['answer'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			$this->redirect($this->url->link('survey/answer', 'token=' . $this->session->data['token'] . $url, 'SSL'));
    	}

    	$this->getList();
  	}

  	private function getList() {
		if (isset($this->request->get['filter_answer_id'])) {
			$filter_answer_id = $this->request->get['filter_answer_id'];
		} else {
			$filter_answer_id = null;
		}
		
		if (isset($this->request->get['filter_survey_id'])) {
			$filter_survey_id = $this->request->get['filter_survey_id'];
		} else {
			$filter_survey_id = $this->session->data['config_survey_id'];
		}
		
		if (isset($this->request->get['filter_question_id'])) {
			$filter_question_id = $this->request->get['filter_question_id'];
		} else {
			$filter_question_id = null;
		}

		if (isset($this->request->get['filter_customer'])) {
			$filter_customer = $this->request->get['filter_customer'];
		} else {
			$filter_customer = null;
		}
		
		if (isset($this->request->get['filter_email'])) {
			$filter_email = $this->request->get['filter_email'];
		} else {
			$filter_email = null;
		}
		
		if (isset($this->request->get['filter_date_added'])) {
			$filter_date_added = $this->request->get['filter_date_added'];
		} else {
			$filter_date_added = null;
		}
		
		if (isset($this->request->get['filter_date_modified'])) {
			$filter_date_modified = $this->request->get['filter_date_modified'];
		} else {
			$filter_date_modified = null;
		}

		if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} else {
			$sort = 'o.answer_id';
		}

		if (isset($this->request->get['answer'])) {
			$answer = $this->request->get['answer'];
		} else {
			$answer = 'DESC';
		}
		
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}
				
		$url = '';

		if (isset($this->request->get['filter_answer_id'])) {
			$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
		}
		
		if (isset($this->request->get['filter_survey_id'])) {
			$url .= '&filter_survey_id=' . $this->request->get['filter_survey_id'];
		}
		
		if (isset($this->request->get['filter_question_id'])) {
			$url .= '&filter_question_id=' . $this->request->get['filter_question_id'];
		}
		
		if (isset($this->request->get['filter_customer'])) {
			$url .= '&filter_customer=' . $this->request->get['filter_customer'];
		}
		
		if (isset($this->request->get['filter_email'])) {
			$url .= '&filter_email=' . $this->request->get['filter_email'];
		}
					
		if (isset($this->request->get['filter_date_added'])) {
			$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
		}
		
		if (isset($this->request->get['filter_date_modified'])) {
			$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
		}

		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}

		if (isset($this->request->get['answer'])) {
			$url .= '&answer=' . $this->request->get['answer'];
		}
		
		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}

  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . $url, 'SSL'),
      		'separator' => ' :: '
   		);

		$this->data['invoice'] = $this->url->link('survey/answer/invoice', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['delete'] = $this->url->link('survey/answer/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');

		$this->data['answers'] = array();

		$data = array(
			'filter_answer_id'        => $filter_answer_id,
			'filter_survey_id'        => $filter_survey_id,
			'filter_question_id'        => $filter_question_id,
			'filter_customer'	     => $filter_customer,
			'filter_email'	     => $filter_email,
			'filter_date_added'      => $filter_date_added,
			'filter_date_modified'   => $filter_date_modified,
			'sort'                   => $sort,
			'answer'                  => $answer,
			'start'                  => ($page - 1) * $this->config->get('config_admin_limit'),
			'limit'                  => $this->config->get('config_admin_limit')
		);

		$answer_total = $this->model_survey_answer->getTotalAnswers($data);

		$results = $this->model_survey_answer->getAnswers($data);

    	foreach ($results as $result) {
			$action = array();
			
			$action[] = array(
				'text' => $this->language->get('text_view'),
				'href' => $this->url->link('survey/answer/info', 'token=' . $this->session->data['token'] . '&answer_id=' . $result['answer_id'] . $url, 'SSL')
			);

			$this->data['answers'][] = array(
				'answer_id'      => $result['answer_id'],
				'survey_id'      => $result['survey_id'],
				'question_id'      => $result['question_id'],
				'customer'      => ($result['customer']) ? $result['customer'] :'Guest',
				'email'      => $result['email'],
				'date_added'    => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
				'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
				'selected'      => isset($this->request->post['selected']) && in_array($result['answer_id'], $this->request->post['selected']),
				'action'        => $action
			);
		}

		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_no_results'] = $this->language->get('text_no_results');
		$this->data['text_abandoned_answers'] = $this->language->get('text_abandoned_answers');

		$this->data['column_answer_id'] = $this->language->get('column_answer_id');
		$this->data['column_survey_id'] = $this->language->get('column_survey_id');
		$this->data['column_question_id'] = $this->language->get('column_question_id');
    	$this->data['column_customer'] = $this->language->get('column_customer');
    	$this->data['column_email'] = $this->language->get('column_email');
		$this->data['column_status'] = $this->language->get('column_status');
		$this->data['column_total'] = $this->language->get('column_total');
		$this->data['column_date_added'] = $this->language->get('column_date_added');
		$this->data['column_date_modified'] = $this->language->get('column_date_modified');
		$this->data['column_action'] = $this->language->get('column_action');

		$this->data['button_invoice'] = $this->language->get('button_invoice');
		$this->data['button_delete'] = $this->language->get('button_delete');
		$this->data['button_filter'] = $this->language->get('button_filter');

		$this->data['token'] = $this->session->data['token'];

		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}

		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];

			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}

		$url = '';

		if (isset($this->request->get['filter_answer_id'])) {
			$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
		}
		
		if (isset($this->request->get['filter_survey_id'])) {
			$url .= '&filter_survey_id=' . $this->request->get['filter_survey_id'];
		}
		
		if (isset($this->request->get['filter_question_id'])) {
			$url .= '&filter_question_id=' . $this->request->get['filter_question_id'];
		}
		
		if (isset($this->request->get['filter_customer'])) {
			$url .= '&filter_customer=' . $this->request->get['filter_customer'];
		}
		
		if (isset($this->request->get['filter_email'])) {
			$url .= '&filter_email=' . $this->request->get['filter_email'];
		}
					
		if (isset($this->request->get['filter_date_added'])) {
			$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
		}
		
		if (isset($this->request->get['filter_date_modified'])) {
			$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
		}

		if ($answer == 'ASC') {
			$url .= '&answer=' .  'DESC';
		} else {
			$url .= '&answer=' .  'ASC';
		}

		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}

		$this->data['sort_answer'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=o.answer_id' . $url, 'SSL');
		$this->data['sort_survey'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=o.survey_id' . $url, 'SSL');
		$this->data['sort_question'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=o.question_id' . $url, 'SSL');
		$this->data['sort_customer'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=customer' . $url, 'SSL');
		$this->data['sort_email'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=o.email' . $url, 'SSL');
		$this->data['sort_date_added'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=o.date_added' . $url, 'SSL');
		$this->data['sort_date_modified'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . '&sort=o.date_modified' . $url, 'SSL');

		$url = '';

		if (isset($this->request->get['filter_answer_id'])) {
			$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
		}
		
		if (isset($this->request->get['filter_survey_id'])) {
			$url .= '&filter_survey_id=' . $this->request->get['filter_survey_id'];
		}
		
		if (isset($this->request->get['filter_question_id'])) {
			$url .= '&filter_question_id=' . $this->request->get['filter_question_id'];
		}
		
		if (isset($this->request->get['filter_customer'])) {
			$url .= '&filter_customer=' . $this->request->get['filter_customer'];
		}
		
		if (isset($this->request->get['filter_email'])) {
			$url .= '&filter_email=' . $this->request->get['filter_email'];
		}
					
		if (isset($this->request->get['filter_date_added'])) {
			$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
		}
		
		if (isset($this->request->get['filter_date_modified'])) {
			$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
		}

		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}

		if (isset($this->request->get['answer'])) {
			$url .= '&answer=' . $this->request->get['answer'];
		}

		$pagination = new Pagination();
		$pagination->total = $answer_total;
		$pagination->page = $page;
		$pagination->limit = $this->config->get('config_admin_limit');
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');

		$this->data['pagination'] = $pagination->render();

		$this->data['filter_answer_id'] = $filter_answer_id;
		$this->data['filter_survey_id'] = $filter_survey_id;
		$this->data['filter_question_id'] = $filter_question_id;		
		$this->data['filter_customer'] = $filter_customer;
		$this->data['filter_email'] = $filter_email;
		$this->data['filter_date_added'] = $filter_date_added;
		$this->data['filter_date_modified'] = $filter_date_modified;


		$this->data['sort'] = $sort;
		$this->data['answer'] = $answer;

		$this->template = 'survey/answer_list.tpl';
		$this->children = array(
			'common/header',
			'common/footer',
		);
		
		$this->response->setOutput($this->render());
  	}

  	public function getForm() {
		$this->data['heading_title'] = $this->language->get('heading_title');
		 
		$this->data['text_default'] = $this->language->get('text_default');
		$this->data['text_select'] = $this->language->get('text_select');
		$this->data['text_none'] = $this->language->get('text_none');
		$this->data['text_wait'] = $this->language->get('text_wait');
		
		$this->data['entry_store'] = $this->language->get('entry_store');
		$this->data['entry_customer'] = $this->language->get('entry_customer');
		$this->data['entry_firstname'] = $this->language->get('entry_firstname');
		$this->data['entry_lastname'] = $this->language->get('entry_lastname');
		$this->data['entry_email'] = $this->language->get('entry_email');
		$this->data['entry_telephone'] = $this->language->get('entry_telephone');
		$this->data['entry_fax'] = $this->language->get('entry_fax');
		$this->data['entry_address'] = $this->language->get('entry_address');
		$this->data['entry_company'] = $this->language->get('entry_company');
		$this->data['entry_address_1'] = $this->language->get('entry_address_1');
		$this->data['entry_address_2'] = $this->language->get('entry_address_2');
		$this->data['entry_city'] = $this->language->get('entry_city');
		$this->data['entry_postcode'] = $this->language->get('entry_postcode');
		$this->data['entry_zone'] = $this->language->get('entry_zone');
		$this->data['entry_zone_code'] = $this->language->get('entry_zone_code');
		$this->data['entry_country'] = $this->language->get('entry_country');		
		$this->data['entry_product'] = $this->language->get('entry_product');
		$this->data['entry_model'] = $this->language->get('entry_model');
		$this->data['entry_quantity'] = $this->language->get('entry_quantity');
		$this->data['entry_price'] = $this->language->get('entry_price');
		$this->data['entry_affiliate'] = $this->language->get('entry_affiliate');
		$this->data['entry_answer_status'] = $this->language->get('entry_answer_status');
		$this->data['entry_comment'] = $this->language->get('entry_comment');		
		$this->data['entry_shipping'] = $this->language->get('entry_shipping');
		$this->data['entry_payment'] = $this->language->get('entry_payment');
		$this->data['entry_total'] = $this->language->get('entry_total');

		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		$this->data['button_add_product'] = $this->language->get('button_add_product');
		$this->data['button_remove'] = $this->language->get('button_remove');

		$this->data['tab_answer'] = $this->language->get('tab_answer');
		$this->data['tab_product'] = $this->language->get('tab_product');
		$this->data['tab_payment'] = $this->language->get('tab_payment');
		$this->data['tab_shipping'] = $this->language->get('tab_shipping');
		$this->data['tab_total'] = $this->language->get('tab_total');

		$this->data['token'] = $this->session->data['token'];

 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
 		if (isset($this->error['firstname'])) {
			$this->data['error_firstname'] = $this->error['firstname'];
		} else {
			$this->data['error_firstname'] = '';
		}

 		if (isset($this->error['lastname'])) {
			$this->data['error_lastname'] = $this->error['lastname'];
		} else {
			$this->data['error_lastname'] = '';
		}
		
 		if (isset($this->error['email'])) {
			$this->data['error_email'] = $this->error['email'];
		} else {
			$this->data['error_email'] = '';
		}
		
 		if (isset($this->error['telephone'])) {
			$this->data['error_telephone'] = $this->error['telephone'];
		} else {
			$this->data['error_telephone'] = '';
		}

 		if (isset($this->error['shipping_firstname'])) {
			$this->data['error_shipping_firstname'] = $this->error['shipping_firstname'];
		} else {
			$this->data['error_shipping_firstname'] = '';
		}

 		if (isset($this->error['shipping_lastname'])) {
			$this->data['error_shipping_lastname'] = $this->error['shipping_lastname'];
		} else {
			$this->data['error_shipping_lastname'] = '';
		}
				
		if (isset($this->error['shipping_address_1'])) {
			$this->data['error_shipping_address_1'] = $this->error['shipping_address_1'];
		} else {
			$this->data['error_shipping_address_1'] = '';
		}
		
		if (isset($this->error['shipping_city'])) {
			$this->data['error_shipping_city'] = $this->error['shipping_city'];
		} else {
			$this->data['error_shipping_city'] = '';
		}
		
		if (isset($this->error['shipping_postcode'])) {
			$this->data['error_shipping_postcode'] = $this->error['shipping_postcode'];
		} else {
			$this->data['error_shipping_postcode'] = '';
		}
		
		if (isset($this->error['shipping_country'])) {
			$this->data['error_shipping_country'] = $this->error['shipping_country'];
		} else {
			$this->data['error_shipping_country'] = '';
		}
		
		if (isset($this->error['shipping_zone'])) {
			$this->data['error_shipping_zone'] = $this->error['shipping_zone'];
		} else {
			$this->data['error_shipping_zone'] = '';
		}

 		if (isset($this->error['payment_firstname'])) {
			$this->data['error_payment_firstname'] = $this->error['payment_firstname'];
		} else {
			$this->data['error_payment_firstname'] = '';
		}

 		if (isset($this->error['payment_lastname'])) {
			$this->data['error_payment_lastname'] = $this->error['payment_lastname'];
		} else {
			$this->data['error_payment_lastname'] = '';
		}
				
		if (isset($this->error['payment_address_1'])) {
			$this->data['error_payment_address_1'] = $this->error['payment_address_1'];
		} else {
			$this->data['error_payment_address_1'] = '';
		}
		
		if (isset($this->error['payment_city'])) {
			$this->data['error_payment_city'] = $this->error['payment_city'];
		} else {
			$this->data['error_payment_city'] = '';
		}
		
		if (isset($this->error['payment_postcode'])) {
			$this->data['error_payment_postcode'] = $this->error['payment_postcode'];
		} else {
			$this->data['error_payment_postcode'] = '';
		}
		
		if (isset($this->error['payment_country'])) {
			$this->data['error_payment_country'] = $this->error['payment_country'];
		} else {
			$this->data['error_payment_country'] = '';
		}
		
		if (isset($this->error['payment_zone'])) {
			$this->data['error_payment_zone'] = $this->error['payment_zone'];
		} else {
			$this->data['error_payment_zone'] = '';
		}
				
		$url = '';

		if (isset($this->request->get['filter_answer_id'])) {
			$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
		}
		
		if (isset($this->request->get['filter_customer'])) {
			$url .= '&filter_customer=' . $this->request->get['filter_customer'];
		}
											
		if (isset($this->request->get['filter_answer_status_id'])) {
			$url .= '&filter_answer_status_id=' . $this->request->get['filter_answer_status_id'];
		}
		
		if (isset($this->request->get['filter_total'])) {
			$url .= '&filter_total=' . $this->request->get['filter_total'];
		}
					
		if (isset($this->request->get['filter_date_added'])) {
			$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
		}
		
		if (isset($this->request->get['filter_date_modified'])) {
			$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
		}

		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}

		if (isset($this->request->get['answer'])) {
			$url .= '&answer=' . $this->request->get['answer'];
		}
		
		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
			'separator' => false
		);

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('survey/answer', 'token=' . $this->session->data['token'], 'SSL'),				
			'separator' => ' :: '
		);

		if (!isset($this->request->get['answer_id'])) {
			$this->data['action'] = $this->url->link('survey/answer/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
		} else {
			$this->data['action'] = $this->url->link('survey/answer/update', 'token=' . $this->session->data['token'] . '&answer_id=' . $this->request->get['answer_id'] . $url, 'SSL');
		}
		
		$this->data['cancel'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . $url, 'SSL');

    	if (isset($this->request->get['answer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
      		$answer_info = $this->model_survey_answer->getAnswer($this->request->get['answer_id']);
    	}
			
    	if (isset($this->request->post['store_id'])) {
      		$this->data['store_id'] = $this->request->post['store_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['store_id'] = $answer_info['store_id'];
		} else {
      		$this->data['store_id'] = '';
    	}
		
		$this->load->model('setting/store');
		
		$this->data['stores'] = $this->model_setting_store->getStores();
		
		$this->data['store_url'] = HTTP_CATALOG;
				
		if (isset($this->request->post['customer_id'])) {
			$this->data['customer_id'] = $this->request->post['customer_id'];
		} elseif (isset($answer_info)) {
			$this->data['customer_id'] = $answer_info['customer_id'];
		} else {
			$this->data['customer_id'] = '';
		}
				
		if (isset($this->request->post['customer'])) {
			$this->data['customer'] = $this->request->post['customer'];
		} elseif (isset($answer_info)) {
			$this->data['customer'] = $answer_info['customer'];
		} else {
			$this->data['customer'] = '';
		}
				
    	if (isset($this->request->post['firstname'])) {
      		$this->data['firstname'] = $this->request->post['firstname'];
		} elseif (isset($answer_info)) { 
			$this->data['firstname'] = $answer_info['firstname'];
		} else {
      		$this->data['firstname'] = '';
    	}

    	if (isset($this->request->post['lastname'])) {
      		$this->data['lastname'] = $this->request->post['lastname'];
    	} elseif (isset($answer_info)) { 
			$this->data['lastname'] = $answer_info['lastname'];
		} else {
      		$this->data['lastname'] = '';
    	}

    	if (isset($this->request->post['email'])) {
      		$this->data['email'] = $this->request->post['email'];
    	} elseif (isset($answer_info)) { 
			$this->data['email'] = $answer_info['email'];
		} else {
      		$this->data['email'] = '';
    	}
				
    	if (isset($this->request->post['telephone'])) {
      		$this->data['telephone'] = $this->request->post['telephone'];
    	} elseif (isset($answer_info)) { 
			$this->data['telephone'] = $answer_info['telephone'];
		} else {
      		$this->data['telephone'] = '';
    	}
		
    	if (isset($this->request->post['fax'])) {
      		$this->data['fax'] = $this->request->post['fax'];
    	} elseif (isset($answer_info)) { 
			$this->data['fax'] = $answer_info['fax'];
		} else {
      		$this->data['fax'] = '';
    	}	

		$this->load->model('sale/customer');

		if (isset($this->request->post['customer_id'])) {
			$this->data['addresses'] = $this->model_sale_customer->getAddresses($this->request->post['customer_id']);
		} elseif (isset($answer_info)) {
			$this->data['addresses'] = $this->model_sale_customer->getAddresses($answer_info['customer_id']);
		} else {
			$this->data['addresses'] = array();
		}
			
    	if (isset($this->request->post['shipping_firstname'])) {
      		$this->data['shipping_firstname'] = $this->request->post['shipping_firstname'];
		} elseif (isset($answer_info)) { 
			$this->data['shipping_firstname'] = $answer_info['shipping_firstname'];
		} else {
      		$this->data['shipping_firstname'] = '';
    	}

    	if (isset($this->request->post['shipping_lastname'])) {
      		$this->data['shipping_lastname'] = $this->request->post['shipping_lastname'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_lastname'] = $answer_info['shipping_lastname'];
		} else {
      		$this->data['shipping_lastname'] = '';
    	}

    	if (isset($this->request->post['shipping_company'])) {
      		$this->data['shipping_company'] = $this->request->post['shipping_company'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_company'] = $answer_info['shipping_company'];
		} else {
      		$this->data['shipping_company'] = '';
    	}

    	if (isset($this->request->post['shipping_address_1'])) {
      		$this->data['shipping_address_1'] = $this->request->post['shipping_address_1'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_address_1'] = $answer_info['shipping_address_1'];
		} else {
      		$this->data['shipping_address_1'] = '';
    	}

    	if (isset($this->request->post['shipping_address_2'])) {
      		$this->data['shipping_address_2'] = $this->request->post['shipping_address_2'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_address_2'] = $answer_info['shipping_address_2'];
		} else {
      		$this->data['shipping_address_2'] = '';
    	}
		
    	if (isset($this->request->post['shipping_city'])) {
      		$this->data['shipping_city'] = $this->request->post['shipping_city'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_city'] = $answer_info['shipping_city'];
		} else {
      		$this->data['shipping_city'] = '';
    	}
		
    	if (isset($this->request->post['shipping_postcode'])) {
      		$this->data['shipping_postcode'] = $this->request->post['shipping_postcode'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_postcode'] = $answer_info['shipping_postcode'];
		} else {
      		$this->data['shipping_postcode'] = '';
    	}
				
    	if (isset($this->request->post['shipping_country_id'])) {
      		$this->data['shipping_country_id'] = $this->request->post['shipping_country_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_country_id'] = $answer_info['shipping_country_id'];
		} else {
      		$this->data['shipping_country_id'] = '';
    	}		
	    
		if (isset($this->request->post['shipping_zone_id'])) {
      		$this->data['shipping_zone_id'] = $this->request->post['shipping_zone_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_zone_id'] = $answer_info['shipping_zone_id'];
		} else {
      		$this->data['shipping_zone_id'] = '';
    	}	
		
    	if (isset($this->request->post['shipping_method'])) {
      		$this->data['shipping_method'] = $this->request->post['shipping_method'];
    	} elseif (isset($answer_info)) { 
			$this->data['shipping_method'] = $answer_info['shipping_method'];
		} else {
      		$this->data['shipping_method'] = '';
    	}	
				
    	if (isset($this->request->post['payment_firstname'])) {
      		$this->data['payment_firstname'] = $this->request->post['payment_firstname'];
		} elseif (isset($answer_info)) { 
			$this->data['payment_firstname'] = $answer_info['payment_firstname'];
		} else {
      		$this->data['payment_firstname'] = '';
    	}

    	if (isset($this->request->post['payment_lastname'])) {
      		$this->data['payment_lastname'] = $this->request->post['payment_lastname'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_lastname'] = $answer_info['payment_lastname'];
		} else {
      		$this->data['payment_lastname'] = '';
    	}

    	if (isset($this->request->post['payment_company'])) {
      		$this->data['payment_company'] = $this->request->post['payment_company'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_company'] = $answer_info['payment_company'];
		} else {
      		$this->data['payment_company'] = '';
    	}

    	if (isset($this->request->post['payment_address_1'])) {
      		$this->data['payment_address_1'] = $this->request->post['payment_address_1'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_address_1'] = $answer_info['payment_address_1'];
		} else {
      		$this->data['payment_address_1'] = '';
    	}

    	if (isset($this->request->post['payment_address_2'])) {
      		$this->data['payment_address_2'] = $this->request->post['payment_address_2'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_address_2'] = $answer_info['payment_address_2'];
		} else {
      		$this->data['payment_address_2'] = '';
    	}
		
    	if (isset($this->request->post['payment_city'])) {
      		$this->data['payment_city'] = $this->request->post['payment_city'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_city'] = $answer_info['payment_city'];
		} else {
      		$this->data['payment_city'] = '';
    	}

    	if (isset($this->request->post['payment_postcode'])) {
      		$this->data['payment_postcode'] = $this->request->post['payment_postcode'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_postcode'] = $answer_info['payment_postcode'];
		} else {
      		$this->data['payment_postcode'] = '';
    	}
				
    	if (isset($this->request->post['payment_country_id'])) {
      		$this->data['payment_country_id'] = $this->request->post['payment_country_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_country_id'] = $answer_info['payment_country_id'];
		} else {
      		$this->data['payment_country_id'] = '';
    	}		
	    
		if (isset($this->request->post['payment_zone_id'])) {
      		$this->data['payment_zone_id'] = $this->request->post['payment_zone_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_zone_id'] = $answer_info['payment_zone_id'];
		} else {
      		$this->data['payment_zone_id'] = '';
    	}
		
		$this->load->model('localisation/country');
		
		$this->data['countries'] = $this->model_localisation_country->getCountries();															
		
    	if (isset($this->request->post['payment_method'])) {
      		$this->data['payment_method'] = $this->request->post['payment_method'];
    	} elseif (isset($answer_info)) { 
			$this->data['payment_method'] = $answer_info['payment_method'];
		} else {
      		$this->data['payment_method'] = '';
    	}
		
		if (isset($this->request->post['affiliate_id'])) {
      		$this->data['affiliate_id'] = $this->request->post['affiliate_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['affiliate_id'] = $answer_info['affiliate_id'];
		} else {
      		$this->data['affiliate_id'] = '';
    	}
		
		if (isset($this->request->post['affiliate'])) {
      		$this->data['affiliate'] = $this->request->post['affiliate'];
    	} elseif (isset($answer_info)) { 
			$this->data['affiliate'] = $answer_info['affiliate_firstname'] . '' . $answer_info['affiliate_lastname'];
		} else {
      		$this->data['affiliate'] = '';
    	}
				
		if (isset($this->request->post['answer_status_id'])) {
      		$this->data['answer_status_id'] = $this->request->post['answer_status_id'];
    	} elseif (isset($answer_info)) { 
			$this->data['answer_status_id'] = $answer_info['answer_status_id'];
		} else {
      		$this->data['answer_status_id'] = '';
    	}
			
		$this->load->model('localisation/answer_status');
		
		$this->data['answer_statuses'] = $this->model_localisation_answer_status->getAnswerStatuses();	
			
    	if (isset($this->request->post['comment'])) {
      		$this->data['comment'] = $this->request->post['comment'];
    	} elseif (isset($answer_info)) { 
			$this->data['comment'] = $answer_info['comment'];
		} else {
      		$this->data['comment'] = '';
    	}	
		
		if (isset($this->request->post['answer_product'])) {
			$answer_products = $this->request->post['answer_product'];
		} elseif (isset($answer_info)) {
			$answer_products = $this->model_survey_answer->getAnswerProducts($this->request->get['answer_id']);			
		} else {
			$answer_products = array();
		}
		
		$this->load->model('catalog/product');
		
		$this->data['answer_products'] = array();		
		
		foreach ($answer_products as $answer_product) {
			$product_info = $this->model_catalog_product->getProduct($answer_product['product_id']);
			
			if ($product_info) {
				$option_data = array();
				
				//$this->data['answer_products'][] = $this->model_survey_answer->getAnswerOptions($this->request->get['answer_id'], $product_option['option_id']);	
				
				$product_options = $this->model_catalog_product->getProductOptions($answer_product['product_id']);	
				
				foreach ($product_options as $product_option) {
					if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox') {
						$option_value_data = array();
						
						foreach ($product_option['product_option_value'] as $product_option_value) {
							$option_value_data[] = array(
								'product_option_value_id' => $product_option_value['product_option_value_id'],
								'option_value_id'         => $product_option_value['option_value_id'],
								'name'                    => $product_option_value['name'],
								'price'                   => (float)$product_option_value['price'] ? $this->currency->format($product_option_value['price'], $this->config->get('config_currency')) : false,
								'price_prefix'            => $product_option_value['price_prefix']
							);	
						}
						
						$option_data[] = array(
							'product_option_id' => $product_option['product_option_id'],
							'option_id'         => $product_option['option_id'],
							'name'              => $product_option['name'],
							'type'              => $product_option['type'],
							'option_value'      => $option_value_data,
							'required'          => $product_option['required']
						);	
					} else {
						$option_data[] = array(
							'product_option_id' => $product_option['product_option_id'],
							'option_id'         => $product_option['option_id'],
							'name'              => $product_option['name'],
							'type'              => $product_option['type'],
							'option_value'      => $product_option['option_value'],
							'required'          => $product_option['required']
						);				
					}
				}
				
				$this->data['answer_products'][] = array(
					'answer_product_id' => $answer_product['answer_product_id'],
					'answer_id'         => $answer_product['answer_id'],
					'product_id'       => $product_info['product_id'],
					'name'             => $product_info['name'],
					'model'            => $product_info['model'],
					'option'           => $option_data,
					'quantity'         => $answer_product['quantity'],
					'price'            => $answer_product['price'],
					'total'            => $answer_product['total'],
					'tax'              => $answer_product['tax']
				);
			}
		}
		   
		if (isset($this->request->post['answer_total'])) {
      		$this->data['answer_totals'] = $this->request->post['answer_total'];
    	} elseif (isset($answer_info)) { 
			$this->data['answer_totals'] = $this->model_survey_answer->getAnswerTotals($this->request->get['answer_id']);
		} else {
      		$this->data['answer_totals'] = array();
    	}	
		
		$this->template = 'survey/answer_form.tpl';
		$this->children = array(
			'common/header',
			'common/footer',
		);
		
		$this->response->setOutput($this->render());
  	}
	
  	private function validateForm() {
    	if (!$this->user->hasPermission('modify', 'survey/answer')) {
      		$this->error['warning'] = $this->language->get('error_permission');
    	}

    	if ((strlen(utf8_decode($this->request->post['firstname'])) < 1) || (strlen(utf8_decode($this->request->post['firstname'])) > 32)) {
      		$this->error['firstname'] = $this->language->get('error_firstname');
    	}

    	if ((strlen(utf8_decode($this->request->post['lastname'])) < 1) || (strlen(utf8_decode($this->request->post['lastname'])) > 32)) {
      		$this->error['lastname'] = $this->language->get('error_lastname');
    	}

    	if ((strlen(utf8_decode($this->request->post['email'])) > 96) || (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL))) {
      		$this->error['email'] = $this->language->get('error_email');
    	}
		
    	if ((strlen(utf8_decode($this->request->post['telephone'])) < 3) || (strlen(utf8_decode($this->request->post['telephone'])) > 32)) {
      		$this->error['telephone'] = $this->language->get('error_telephone');
    	}

    	if ((strlen(utf8_decode($this->request->post['shipping_firstname'])) < 1) || (strlen(utf8_decode($this->request->post['shipping_firstname'])) > 32)) {
      		$this->error['shipping_firstname'] = $this->language->get('error_firstname');
    	}

    	if ((strlen(utf8_decode($this->request->post['shipping_lastname'])) < 1) || (strlen(utf8_decode($this->request->post['shipping_lastname'])) > 32)) {
      		$this->error['shipping_lastname'] = $this->language->get('error_lastname');
    	}
		
    	if ((strlen(utf8_decode($this->request->post['shipping_address_1'])) < 3) || (strlen(utf8_decode($this->request->post['shipping_address_1'])) > 128)) {
      		$this->error['shipping_address_1'] = $this->language->get('error_address_1');
    	}

    	if ((strlen(utf8_decode($this->request->post['shipping_city'])) < 3) || (strlen(utf8_decode($this->request->post['shipping_city'])) > 128)) {
      		$this->error['shipping_city'] = $this->language->get('error_city');
    	}

		$this->load->model('localisation/country');
		
		$country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
		
		if ($country_info && $country_info['postcode_required'] && (strlen(utf8_decode($this->request->post['shipping_postcode'])) < 2) || (strlen(utf8_decode($this->request->post['shipping_postcode'])) > 10)) {
			$this->error['shipping_postcode'] = $this->language->get('error_postcode');
		}

    	if ($this->request->post['shipping_country_id'] == '') {
      		$this->error['shipping_country'] = $this->language->get('error_country');
    	}
		
    	if ($this->request->post['shipping_zone_id'] == '') {
      		$this->error['shipping_zone'] = $this->language->get('error_zone');
    	}
		
    	if ((strlen(utf8_decode($this->request->post['payment_firstname'])) < 1) || (strlen(utf8_decode($this->request->post['payment_firstname'])) > 32)) {
      		$this->error['payment_firstname'] = $this->language->get('error_firstname');
    	}

    	if ((strlen(utf8_decode($this->request->post['payment_lastname'])) < 1) || (strlen(utf8_decode($this->request->post['payment_lastname'])) > 32)) {
      		$this->error['payment_lastname'] = $this->language->get('error_lastname');
    	}

    	if ((strlen(utf8_decode($this->request->post['payment_address_1'])) < 3) || (strlen(utf8_decode($this->request->post['payment_address_1'])) > 128)) {
      		$this->error['payment_address_1'] = $this->language->get('error_address_1');
    	}

    	if ((strlen(utf8_decode($this->request->post['payment_city'])) < 3) || (strlen(utf8_decode($this->request->post['payment_city'])) > 128)) {
      		$this->error['payment_city'] = $this->language->get('error_city');
    	}

		$country_info = $this->model_localisation_country->getCountry($this->request->post['payment_country_id']);
		
		if ($country_info && $country_info['postcode_required'] && (strlen(utf8_decode($this->request->post['payment_postcode'])) < 2) || (strlen(utf8_decode($this->request->post['payment_postcode'])) > 10)) {
			$this->error['payment_postcode'] = $this->language->get('error_postcode');
		}

    	if ($this->request->post['payment_country_id'] == '') {
      		$this->error['payment_country'] = $this->language->get('error_country');
    	}
		
    	if ($this->request->post['payment_zone_id'] == '') {
      		$this->error['payment_zone'] = $this->language->get('error_zone');
    	}		

		if ($this->error && !isset($this->error['warning'])) {
			$this->error['warning'] = $this->language->get('error_warning');
		}
		
		if (!$this->error) {
	  		return true;
		} else {
	  		return false;
		}
  	}
  	
  	public function info() {
  		$this->load->language('survey/answer');

		$this->document->setTitle($this->language->get('heading_title'));
		
		$url = "";
		
		if (isset($this->request->get['filter_answer_id'])) {
			$url .= '&filter_answer_id=' . $this->request->get['filter_answer_id'];
		}
		
		if (isset($this->request->get['filter_survey_id'])) {
			$url .= '&filter_survey_id=' . $this->request->get['filter_survey_id'];
		}
		
		if (isset($this->request->get['filter_question_id'])) {
			$url .= '&filter_question_id=' . $this->request->get['filter_question_id'];
		}
		
		if (isset($this->request->get['filter_customer'])) {
			$url .= '&filter_customer=' . $this->request->get['filter_customer'];
		}
		
		if (isset($this->request->get['filter_email'])) {
			$url .= '&filter_email=' . $this->request->get['filter_email'];
		}
					
		if (isset($this->request->get['filter_date_added'])) {
			$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
		}
		
		if (isset($this->request->get['filter_date_modified'])) {
			$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
		}

		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}

		if (isset($this->request->get['answer'])) {
			$url .= '&answer=' . $this->request->get['answer'];
		}
		
		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}
		
		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . $url, 'SSL'),
      		'separator' => ' :: '
   		);
   		
   		$this->data['token'] = $this->session->data['token'];

		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}

		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];

			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}
		
		$answer_id = $this->request->get['answer_id'];
		
		$this->load->model('survey/answer');
		$get_answer = $this->model_survey_answer->getAnswer($answer_id);		
		
		$customer_id = $get_answer['customer_id'];
		$survey_id = $get_answer['survey_id'];
		$question_id = $get_answer['question_id'];
		
		
		$this->load->model('sale/customer');
		$user_info = $this->model_sale_customer->getCustomer($customer_id);
		
		$this->load->model('survey/survey');
		$survey_info = $this->model_survey_survey->getSurvey($survey_id);
		
		$this->load->model('survey/question');
		$question_info = $this->model_survey_question->getQuestion($question_id);
		$question_desc = $this->model_survey_question->getQuestionDescriptions($question_id);
		
		$question_info = array_merge($question_info, $question_desc['1']);
		
//		print_r($question_info);
		
		switch($question_info['qtype']) {
      		case 'text':
      		case 'textarea':
      		
      			$question_data = array(
      				'filter_survey_id' => $survey_id,
      				'filter_question_id' => $question_id,
      				'filter_customer_id' => $customer_id,
      				'filter_check_answer' => 'not-empty'
	      		);
	      			
	      		$total_participant = $this->model_survey_survey->getTotalParticipent($question_data);
	      		
	      		$check_answer = "not-empty";
	      		
	      		$answer[] = array(
					'text' => 'Have Some Text',
					'value' => $total_participant,
					'link' => $this->url->link('survey/survey/participents', 'token=' . $this->session->data['token'] . '&survey_id=' . $survey_id . '&question_id=' . $question_id . '&filter_answer=' . $check_answer)				
				);
      		break;
      		case 'checkbox':
      		case 'radio':
	      		$question_info['lable'] = str_replace("\r","", $question_info['lable']);
	      		$all_lables = explode("\n", $question_info['lable']);
	      		if(!empty($question_info['value'])) {
	      			$question_info['value'] = str_replace("\r","", $question_info['value']);
	      			$all_values = explode("\n", $question_info['value']);
	      		} else {
	      			$all_values = $all_lables;
	      		}      			
	      		
	      		if(!empty($check_answer['answer']))
	      			$default_value = $check_answer['answer'];
	      		else
	      			$default_value = $question_info['default'];
	      		
	      		foreach($all_lables as $key => $each_value) {
	      			      			
	      			$default = 0;
	      			if($default_value == $all_values[$key])
	      				$default = 1;
	      				
	      		    $options[] = array(
		      			'lable' => $all_lables[$key],
		      			'value' => $all_values[$key],
		      			'default' => $default
		      		);	
	      		}
	      		
	      		foreach($options as $each_option) {
	      			
	      			$question_data = array(
	      				'filter_survey_id' => $survey_id,
	      				'filter_question_id' => $question_id,
	      				'filter_customer_id' => $customer_id,
	      				'filter_answer' => $each_option['value']
	      			);
	      			
	      			$total_participant = $this->model_survey_survey->getTotalParticipent($question_data);
	
					$answer[] = array(
						'text' => $each_option['lable'],
						'value' => $total_participant,
						'link' => $this->url->link('survey/survey/participents', 'token=' . $this->session->data['token'] . '&survey_id=' . $survey_id . '&question_id=' . $question_id . '&filter_answer=' . urlencode($each_option['value']))
					);      			
	      		}
	      		
    			break;
    			case 'default' :
    			case 'lable' :
    			$answer = array();
    			break;
  		}
		
		$checked_answer = "";
		foreach($answer as $check) {
			if($check['value']) {
				if($check['text'] == 'Have Some Text')
					$checked_answer = $get_answer['answer'];
				else
					$checked_answer = $check['text'];
				break;
			}
		}
		
//		$checked_answer;
//		print_r($answer);		
//		print_r($get_answer);
//		print_r($user_info);
//		print_r($survey_info);
//		print_r($question_info);
		
		$this->data['heading_title'] = $this->language->get('heading_title') . ": " . $user_info['firstname']." ".$user_info['lastname']." (".$user_info['email'].")";
		
		$this->data['button_back'] = $this->language->get('button_back');
   		
   		$this->data['back'] = $this->url->link('survey/answer', 'token=' . $this->session->data['token'] . $url, 'SSL');
				
		$this->data['survey'] = $survey_info['title'];
		$this->data['question'] = $question_info['title'];
		
		
		$this->data['answer'] = $checked_answer;
		
  		$this->template = 'common/page.tpl';
  		
		$this->children = array(
			'common/header',
			'common/footer',
		);
		
		$this->response->setOutput($this->render());
  	}    
	
   	private function validateDelete() {
    	if (!$this->user->hasPermission('modify', 'survey/answer')) {
			$this->error['warning'] = $this->language->get('error_permission');
    	}

		if (!$this->error) {
	  		return true;
		} else {
	  		return false;
		}
  	}	
}
?>